// 引入路由组件
import Home from '@/pages/Home';
import Search from '@/pages/Search';
import Login from '@/pages/Login';
import Register from '@/pages/Register';
import Detail from '@/pages/Detail';
import AddCartSuccess from '@/pages/AddCartSuccess'
import ShopCart from '@/pages/ShopCart';
import Trade from '@/pages/Trade'
import Pay from "@/pages/Pay";
import PaySuccess from "@/pages/PaySuccess"
import Center from "@/pages/Center";
// 引入二级路由组件
import MyOrder from '@/pages/Center/myOrder'
import GroupOrder from '@/pages/Center/groupOrder'
export default [
    {
        path: "/center",
        component: Center,
        name: "Center",
        meta: { show: true },
        children: [
            {
                path: 'myorder',
                component: MyOrder,
            },
            {
                path: 'grouporder',
                component: GroupOrder
            },
            {
                path: '/center',
                redirect: '/center/myorder'
            }
        ]
    },
    {
        path: "/paysuccess",
        component: PaySuccess,
        name: "PaySuccess",
        meta: { show: true }

    },
    {
        path: "/pay",
        component: Pay,
        name: "Pay",
        meta: { show: true },
        beforeEnter: (to, from, next) => {
            if (from.path == "/trade") {
                next();
            } else {
                next(false);
            }
        }
    },
    {
        path: "/trade",
        component: Trade,
        name: "Trade",
        meta: { show: true },
        beforeEnter: (to, from, next) => {
            // 去交易界面必须是从购物车来的
            if (from.path == "/shopcart") {
                next();
            } else {
                // 其他路由
                next(false);
                // 中断当前导航
            }
        }
    },
    {
        path: "/shopcart",
        component: ShopCart,
        name: "ShopCart",
        meta: { show: true },
    },
    {
        path: "/addcartsuccess",
        component: AddCartSuccess,
        name: "addcartsuccess",
        meta: { show: true },
    },
    {
        path: "/home",
        component: Home,
        meta: {
            show: true,
            show2: false,
        }
    },
    {
        path: "/search/:keyword?",
        component: Search,
        meta: { show: true },
        name: 'search',
        props: true
    },
    {
        path: "/login",
        component: Login
        , meta: { show: false }
    },
    {
        path: "/register",
        component: Register
        , meta: { show: false }
    },
    {
        path: "/detail/:skuid",
        component: Detail,
    },
    //当我们最开始的时候显示出来的
    {
        path: '*',
        redirect: "/home",
    },
]
